import common from '../vendor/common'
import '../scss/user_find_house.scss'
import { findHouse } from '../vendor/api'
try{
    const mui = common.mui
    var data = {}
    var tel = null //电话号码
    var appellation = null //称谓
    var demand = null //需求
    mui.init({
        swipeBack:false //启用右滑关闭功能
    });
    mui.plusReady(function(){
        window.addEventListener('find', function(e){
            data = {}
            tel = null
            appellation = null
            demand = null
            mui('#tel')[0].value = null
            mui('#appellation')[0].value = null
            mui('#requirement')[0].value = null
        })
        // 提交
        mui('.loginOut').on('tap','button',function(){
            // 获取输入框里的值
            tel = mui('#tel')[0].value
            appellation = mui('#appellation')[0].value
            demand = mui('#requirement')[0].value
            data.tel = tel
            data.name = appellation
            data.remark = demand
            data.page_source = '个人中心-委托找房'
            data.source = 5
            data.demand = 2
            // 隐藏键盘
            mui('#tel')[0].blur()
            mui('#appellation')[0].blur()
            mui('#requirement')[0].blur()
            // 验证
            if(!appellation || appellation.trim() == ''){
                mui.alert('请输入称谓')
            } else if(!tel || tel.trim() == ''){
                mui.alert('请输入手机号码')
            } else {
                findHouse(data).then((res) => {
                    // console.log(JSON.stringify(res))
                    if(res.data){
                        mui.toast('信息提交成功，楚楼网30分钟内联系您')
                        // 获取当前页面webview
                        var ws=plus.webview.currentWebview();
                        plus.webview.hide(ws);
                    }
                })
            } 
        })
    })
}catch(e){
    console.log('user_find_house.html出错了')
}